home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 27 (1992-03)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 27 (1992-03)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / Programming / Random / random.h < prev    next >
C/C++ Source or Header  |  1992-03-30  |  1KB  |  40 lines

  1.  /*
  2.     ;------------------------------------------------------------------
  3.     ; Code typed by Peter Thompson on 11 Feb. 92, although written
  4.     ; several days earlier. This code is "wareware"; if you use it in
  5.     ; any of your programs for which you want money, send me a copy at:
  6.     ; 33 Pleasant Street/Pascoe Vale 3044/Australia
  7.     ;------------------------------------------------------------------
  8.     ; $MUSIC = "The Black Sorrows/Hold On To Me"
  9.     ;------------------------------------------------------------------
  10.     ; Algorithm adapted from "Algorithms in C", Robert Sedgewick,
  11.     ; pub. Addison-Wesley 1990 (he got it from Knuth, vol. 2?)
  12.     ;------------------------------------------------------------------
  13.  */
  14.  
  15. #ifndef ULONG
  16.   typedef unsigned long int ULONG;
  17. #endif
  18.  
  19. #define MAXRNDNUM 2147483648
  20.  
  21. typedef struct randstate {
  22.     ULONG rs_Index;
  23.     ULONG rs_State[64];
  24. } RandState;
  25.  
  26. extern void rand32init(RandState *,ULONG);
  27.  /* Call this function to initialise to a particular sequence of random
  28. numbers.
  29.  */
  30. extern ULONG rndx32(RandState *);
  31.  /* additive congruential method using exclusive-or
  32.  */
  33. extern ULONG rnda32(RandState *);
  34.  /* additive congruential method using addition modulo MAXRNDNUM
  35.  */
  36.  
  37.  /* The number of numbers before the sequence generated by rnda32 or rndx32
  38. begins to repeat itself is at least 2^55-1, or more than 36028797018700000.
  39.  */
  40.